﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class UISTOCK : ViewBase
    {
        public VICC_STOCK TMV
        {
            get
            {
                return (VICC_STOCK)MV;
            }
        }
        #region ==dwKEY===========
        public static readonly DependencyProperty dwKEYProperty = DependencyProperty.Register("dwKEY",
            typeof(DataRowView), typeof(UISTOCK),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwKEYChanged));
        public DataRowView dwKEY
        {
            get
            {
                return (DataRowView)GetValue(dwKEYProperty);
            }
            set
            {
                SetValue(dwKEYProperty, value);
            }
        }
        private static void OndwKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UISTOCK;
            if (src != null)
            {
                src.dwKEY = (DataRowView)e.NewValue;
            }
        }
        #endregion
        #region ==dwSTOCK===========
        public static readonly DependencyProperty dwSTOCKProperty = DependencyProperty.Register("dwSTOCK",
            typeof(DataRowView), typeof(UISTOCK),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwSTOCKChanged));
        public DataRowView dwSTOCK
        {
            get
            {
                return (DataRowView)GetValue(dwSTOCKProperty);
            }
            set
            {
                SetValue(dwSTOCKProperty, value);
            }
        }
        private static void OndwSTOCKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UISTOCK;
            if (src != null)
            {
                src.dwSTOCK = (DataRowView)e.NewValue;
            }
        }
        #endregion

        #region ==QCKEY===========
        public static readonly DependencyProperty QCKEYProperty = DependencyProperty.Register("QCKEY",
            typeof(string), typeof(UISTOCK),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnQCKEYChanged));
        public string QCKEY
        {
            get
            {
                return (string)GetValue(QCKEYProperty);
            }
            set
            {
                SetValue(QCKEYProperty, value);
            }
        }
        private static void OnQCKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UISTOCK;
            if (src != null)
            {
                src.QCKEY = (string)e.NewValue;
            }
        }
        #endregion

        #region ==YBG===========
        public static readonly DependencyProperty YBGProperty = DependencyProperty.Register("YBG",
            typeof(string), typeof(UISTOCK),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnYBGChanged));
        public string YBG
        {
            get
            {
                return (string)GetValue(YBGProperty);
            }
            set
            {
                SetValue(YBGProperty, value);
            }
        }
        private static void OnYBGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UISTOCK;
            if (src != null)
            {
                src.YBG = (string)e.NewValue;
            }
        }
        #endregion

        
        public UISTOCK()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;

        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                KEY = "";
                QCKEY = "";
            }
            else
            {
                KEY = dwMaster["LO"].ToString().Trim().PadRight(2) + dwMaster["LB"].ToString().Trim().PadRight(2)
            + dwMaster["MDATE"].ToString().Trim().PadRight(8) + dwMaster["WAKZ"].ToString().Trim().PadRight(1) + dwMaster["ART"].ToString().Trim().PadRight(20)
            + dwMaster["VAR"].ToString().Trim().PadRight(2) + dwMaster["FARBE"].ToString().Trim().PadRight(10) + dwMaster["FINISH"].ToString().Trim().PadRight(10)
            + dwMaster["DESS"].ToString().Trim().PadRight(10)
            + dwMaster["COLORIT"].ToString().Trim().PadRight(10) + dwMaster["FSIZE"].ToString().Trim().PadRight(7) + dwMaster["FBPART"].ToString().Trim().PadRight(10) + dwMaster["SPPART"].ToString().Trim().PadRight(10)
            + dwMaster["ZWPART"].ToString().Trim().PadRight(10) + dwMaster["BEM1"].ToString().Trim().PadRight(40);
                QCKEY = KEY;
            }
        } 
    }
}
